<?php
//The Widgetization Code (sidebar, under adsense)
if ( function_exists('register_sidebar') ) {
register_sidebar(array('name'=>'Right Sidebar','before_widget' => '<div class="widget">','after_widget' => '</div>','before_title' => '<h2>','after_title' => '</h2>',)); }

//Define the wp_content DIR for backward compatibility
if (!defined('WP_CONTENT_URL'))
	define('WP_CONTENT_URL', get_option('site_url').'/wp-content');
if (!defined('WP_CONTENT_DIR'))
	define('WP_CONTENT_DIR', ABSPATH.'/wp-content');

//Call jQuery, jTabber, and the custom.js file
function load_JS() {
	wp_enqueue_script('jtabber', $src = get_bloginfo('template_url').'/js/jtabber.js', $deps = array('jquery'));
	wp_enqueue_script('custom', $src = get_bloginfo('template_url').'/js/custom.js');
}
add_action('wp_print_scripts','load_JS');
    
//A function to include files throughout the theme
//It checks to see if the file exists first, so as to avoid error messages.
function get_template_file($filename) {
if (file_exists(TEMPLATEPATH."/$filename"))
include(TEMPLATEPATH."/$filename");
}

//Custom Limit-Posts plugin
include(TEMPLATEPATH."/lib/limit-posts.php");

//Custom Breadcrumb plugin
include(TEMPLATEPATH."/lib/breadcrumb.php");

//Custom Header Image code
include(TEMPLATEPATH."/lib/custom-header.php");

//Theme Options Code
include(TEMPLATEPATH."/lib/theme-options.php");

//A simple function to get data stored in a custom field
function get_custom_field($field) {
	global $post;
	$custom_field = get_post_meta($post->ID, $field, true);
	echo $custom_field;
}

//A function to get custom field image attachment...
//if there is none, use default image
function image_attachment($field, $width, $height) {
	global $post;
	$custom_field = get_post_meta($post->ID, $field, true);
	//default fallback URL and PATH
	$default_img = get_bloginfo('template_url').'/images/'.$field.'.png';
	$default_img_path = TEMPLATEPATH.'/images/'.$field.'.png';
	
	if($custom_field) { //if the user set a custom field
		echo '<img src="'.$custom_field.'" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"/>';
	}
	elseif (file_exists($default_img_path)) { //if the fallback image exists
		//echo '<img src="'.$default_img.'" alt="'.get_the_title().'" width="'.$width.'" height="'.$height.'"/>';
	}
	else { //if fallback image does not exist, use a grey block div
		//echo '<div style="background: #CCC; width: '.$width.'px; height: '.$height.'px; color: #000; text-align: center; float: left;">No Image Available</div>';
	}
}

//A Function converts a Category ID # into the Category Name
function prox_cat_name($id) {
	foreach((array)(get_categories()) as $category) {
    	if ($id == $category->cat_ID) { return $category->cat_name; break; }
	}
}

//A Function converts a Category ID # into a link with
//the category URL as the href, and the Category name
//as the anchor text
function prox_cat_link($id) {
	$url = get_category_link($id);
	foreach((array)(get_categories()) as $category) {
    	if ($id == $category->cat_ID) {
    	$name = $category->cat_name;
    	echo '<a href="'. $url .'" title="View all posts filed under '. $name .'">'.$name.'</a>'; 
    	break; }
	}
}

//Footer Attribution Code
function footer_attribution() {
	echo ' &bull; Provided By <a href="http://www.target-info.com">Target Info</a>';
	//echo ' &bull; <a href="http://www.nathanrice.net/proximity/">Proximity News Theme</a> &bull; Design by <a href="http://www.nathanrice.net">Nathan Rice</a>.';
}
add_action('wp_footer', 'footer_attribution');

///Tracking/Analytics Code
function print_tracking() {
	global $wp_theme_options;
	echo stripslashes($wp_theme_options['tracking']);
}
if ($wp_theme_options['tracking']) {
if ($wp_theme_options['tracking_pos'] == "header") {
	add_action('wp_head', 'print_tracking'); }
else { //default
	add_action('wp_footer', 'print_tracking'); } }

//A function to hide the popularity display
function akst_hide_pop() {
        return false;
}
add_action('akpc_display_popularity', 'akst_hide_pop');
?>